package com.xmy.study.listeners;

import com.xmy.study.constants.MqConstants;
import com.xmy.study.respons.ResStudentAccount;
import com.xmy.study.service.IStudentAccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class StudentAccountListener {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    IStudentAccountService iStudentAccountService;


    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = MqConstants.QUEUE_SYNC_STUDENT_ACCOUNT_MATH, durable = "true"),
            exchange = @Exchange(name = MqConstants.EXCHANGE_SYNC_STUDENT_ACCOUNT_FANOUT, type = ExchangeTypes.FANOUT)
    ))
    public void listenDirectQueueAddAccount(ResStudentAccount resStudentAccount) throws InterruptedException {
        System.out.println("消费者english 收到了 direct.queue1的消息：【" + resStudentAccount +"】");
        if (resStudentAccount.getSubjectsId() !=null && resStudentAccount.getSubjectsId().equals(2L)){
            iStudentAccountService.updateAccount(resStudentAccount);
        }
    }


    /*@RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = MqConstants.QUEUE_MATH_ADD_STUDENT_ACCOUNT_Q1, durable = "true"),
            exchange = @Exchange(name = MqConstants.EXCHANGE_MATH_ADD_STUDENT_ACCOUNT_DIRECT, type = ExchangeTypes.DIRECT),
            key = MqConstants.KEY_MATH
    ))
    public void listenDirectQueueAddAccount(ResStudentAccount resStudentAccount) throws InterruptedException {
        System.out.println("消费者english 收到了 direct.queue1的消息：【" + resStudentAccount +"】");
        if (resStudentAccount.getSubjectsId().equals(2L)){
            iStudentAccountService.updateAccount(resStudentAccount);
        }

    }*/

}
